home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251811_mod_dav.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-10-29  |  90.8 KB  |  2,444 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. /*
  56. ** DAV extension module for Apache 2.0.*
  57. */
  58.  
  59. #ifndef _MOD_DAV_H_
  60. #define _MOD_DAV_H_
  61.  
  62. #include "apr_hooks.h"
  63. #include "apr_hash.h"
  64. #include "apr_dbm.h"
  65. #include "apr_tables.h"
  66.  
  67. #include "httpd.h"
  68. #include "util_filter.h"
  69. #include "util_xml.h"
  70.  
  71. #include <limits.h>     /* for INT_MAX */
  72. #include <time.h>       /* for time_t */
  73.  
  74. #ifdef __cplusplus
  75. extern "C" {
  76. #endif
  77.  
  78.  
  79. #define DAV_VERSION             AP_SERVER_BASEREVISION
  80.  
  81. #define DAV_XML_HEADER          "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  82. #define DAV_XML_CONTENT_TYPE    "text/xml; charset=\"utf-8\""
  83.  
  84. #define DAV_READ_BLOCKSIZE      2048    /* used for reading input blocks */
  85.  
  86. #define DAV_RESPONSE_BODY_1     "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>"
  87. #define DAV_RESPONSE_BODY_2     "</title>\n</head><body>\n<h1>"
  88. #define DAV_RESPONSE_BODY_3     "</h1>\n<p>"
  89. #define DAV_RESPONSE_BODY_4     "</p>\n"
  90. #define DAV_RESPONSE_BODY_5     "</body></html>\n"
  91.  
  92. #define DAV_DO_COPY             0
  93. #define DAV_DO_MOVE             1
  94.  
  95.  
  96. #if 1
  97. #define DAV_DEBUG        1
  98. #define DEBUG_CR         "\n"
  99. #define DBG0(f)          ap_log_error(APLOG_MARK, \
  100.                                 APLOG_ERR, 0, NULL, (f))
  101. #define DBG1(f,a1)       ap_log_error(APLOG_MARK, \
  102.                                 APLOG_ERR, 0, NULL, f, a1)
  103. #define DBG2(f,a1,a2)    ap_log_error(APLOG_MARK, \
  104.                                 APLOG_ERR, 0, NULL, f, a1, a2)
  105. #define DBG3(f,a1,a2,a3) ap_log_error(APLOG_MARK, \
  106.                                 APLOG_ERR, 0, NULL, f, a1, a2, a3)
  107. #else
  108. #undef DAV_DEBUG
  109. #define DEBUG_CR        ""
  110. #endif
  111.  
  112. #define DAV_INFINITY    INT_MAX    /* for the Depth: header */
  113.  
  114. /* Create a set of DAV_DECLARE(type), DAV_DECLARE_NONSTD(type) and 
  115.  * DAV_DECLARE_DATA with appropriate export and import tags for the platform
  116.  */
  117. #if !defined(WIN32)
  118. #define DAV_DECLARE(type)            type
  119. #define DAV_DECLARE_NONSTD(type)     type
  120. #define DAV_DECLARE_DATA
  121. #elif defined(DAV_DECLARE_STATIC)
  122. #define DAV_DECLARE(type)            type __stdcall
  123. #define DAV_DECLARE_NONSTD(type)     type
  124. #define DAV_DECLARE_DATA
  125. #elif defined(DAV_DECLARE_EXPORT)
  126. #define DAV_DECLARE(type)            __declspec(dllexport) type __stdcall
  127. #define DAV_DECLARE_NONSTD(type)     __declspec(dllexport) type
  128. #define DAV_DECLARE_DATA             __declspec(dllexport)
  129. #else
  130. #define DAV_DECLARE(type)            __declspec(dllimport) type __stdcall
  131. #define DAV_DECLARE_NONSTD(type)     __declspec(dllimport) type
  132. #define DAV_DECLARE_DATA             __declspec(dllimport)
  133. #endif
  134.  
  135. /* --------------------------------------------------------------------
  136. **
  137. ** ERROR MANAGEMENT
  138. */
  139.  
  140. /*
  141. ** dav_error structure.
  142. **
  143. ** In most cases, mod_dav uses a pointer to a dav_error structure. If the
  144. ** pointer is NULL, then no error has occurred.
  145. **
  146. ** In certain cases, a dav_error structure is directly used. In these cases,
  147. ** a status value of 0 means that an error has not occurred.
  148. **
  149. ** Note: this implies that status != 0 whenever an error occurs.
  150. **
  151. ** The desc field is optional (it may be NULL). When NULL, it typically
  152. ** implies that Apache has a proper description for the specified status.
  153. */
  154. typedef struct dav_error {
  155.     int status;                 /* suggested HTTP status (0 for no error) */
  156.     int error_id;               /* DAV-specific error ID */
  157.     const char *desc;           /* DAV:responsedescription and error log */
  158.  
  159.     int save_errno;             /* copy of errno causing the error */
  160.  
  161.     const char *namespace;      /* [optional] namespace of error */
  162.     const char *tagname;        /* name of error-tag */
  163.  
  164.     struct dav_error *prev;     /* previous error (in stack) */
  165.  
  166. } dav_error;
  167.  
  168. /*
  169. ** Create a new error structure. save_errno will be filled with the current
  170. ** errno value.
  171. */
  172. DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status, 
  173.                                       int error_id, const char *desc);
  174.  
  175.  
  176. /*
  177. ** Create a new error structure with tagname and (optional) namespace;
  178. ** namespace may be NULL, which means "DAV:". save_errno will be
  179. ** filled with the current errno value.
  180. */
  181. DAV_DECLARE(dav_error*) dav_new_error_tag(apr_pool_t *p, int status, 
  182.                                           int error_id, const char *desc,
  183.                                           const char *namespace,
  184.                                           const char *tagname);
  185.  
  186.  
  187. /*
  188. ** Push a new error description onto the stack of errors.
  189. **
  190. ** This function is used to provide an additional description to an existing
  191. ** error.
  192. **
  193. ** <status> should contain the caller's view of what the current status is,
  194. ** given the underlying error. If it doesn't have a better idea, then the
  195. ** caller should pass prev->status.
  196. **
  197. ** <error_id> can specify a new error_id since the topmost description has
  198. ** changed.
  199. */
  200. DAV_DECLARE(dav_error*) dav_push_error(apr_pool_t *p, int status, int error_id,
  201.                                        const char *desc, dav_error *prev);
  202.  
  203.  
  204. /* error ID values... */
  205.  
  206. /* IF: header errors */
  207. #define DAV_ERR_IF_PARSE                100    /* general parsing error */
  208. #define DAV_ERR_IF_MULTIPLE_NOT         101    /* multiple "Not" found */
  209. #define DAV_ERR_IF_UNK_CHAR             102    /* unknown char in header */
  210. #define DAV_ERR_IF_ABSENT               103    /* no locktokens given */
  211. #define DAV_ERR_IF_TAGGED               104    /* in parsing tagged-list */
  212. #define DAV_ERR_IF_UNCLOSED_PAREN       105    /* in no-tagged-list */
  213.  
  214. /* Prop DB errors */
  215. #define DAV_ERR_PROP_BAD_MAJOR          200    /* major version was wrong */
  216. #define DAV_ERR_PROP_READONLY           201    /* prop is read-only */
  217. #define DAV_ERR_PROP_NO_DATABASE        202    /* writable db not avail */
  218. #define DAV_ERR_PROP_NOT_FOUND          203    /* prop not found */
  219. #define DAV_ERR_PROP_BAD_LOCKDB         204    /* could not open lockdb */
  220. #define DAV_ERR_PROP_OPENING            205    /* problem opening propdb */
  221. #define DAV_ERR_PROP_EXEC               206    /* problem exec'ing patch */
  222.  
  223. /* Predefined DB errors */
  224. /* ### any to define?? */
  225.  
  226. /* Predefined locking system errors */
  227. #define DAV_ERR_LOCK_OPENDB             400    /* could not open lockdb */
  228. #define DAV_ERR_LOCK_NO_DB              401    /* no database defined */
  229. #define DAV_ERR_LOCK_CORRUPT_DB         402    /* DB is corrupt */
  230. #define DAV_ERR_LOCK_UNK_STATE_TOKEN    403    /* unknown State-token */
  231. #define DAV_ERR_LOCK_PARSE_TOKEN        404    /* bad opaquelocktoken */
  232. #define DAV_ERR_LOCK_SAVE_LOCK          405    /* err saving locks */
  233.  
  234. /*
  235. ** Some comments on Error ID values:
  236. **
  237. ** The numbers do not necessarily need to be unique. Uniqueness simply means
  238. ** that two errors that have not been predefined above can be distinguished
  239. ** from each other. At the moment, mod_dav does not use this distinguishing
  240. ** feature, but it could be used in the future to collapse <response> elements
  241. ** into groups based on the error ID (and associated responsedescription).
  242. **
  243. ** If a compute_desc is provided, then the error ID should be unique within
  244. ** the context of the compute_desc function (so the function can figure out
  245. ** what to filled into the desc).
  246. **
  247. ** Basically, subsystems can ignore defining new error ID values if they want
  248. ** to. The subsystems *do* need to return the predefined errors when
  249. ** appropriate, so that mod_dav can figure out what to do. Subsystems can
  250. ** simply leave the error ID field unfilled (zero) if there isn't an error
  251. ** that must be placed there.
  252. */
  253.  
  254.  
  255. /* --------------------------------------------------------------------
  256. **
  257. ** HOOK STRUCTURES
  258. **
  259. ** These are here for forward-declaration purposes. For more info, see
  260. ** the section title "HOOK HANDLING" for more information, plus each
  261. ** structure definition.
  262. */
  263.  
  264. /* forward-declare this structure */
  265. typedef struct dav_hooks_propdb dav_hooks_propdb;
  266. typedef struct dav_hooks_locks dav_hooks_locks;
  267. typedef struct dav_hooks_vsn dav_hooks_vsn;
  268. typedef struct dav_hooks_repository dav_hooks_repository;
  269. typedef struct dav_hooks_liveprop dav_hooks_liveprop;
  270. typedef struct dav_hooks_binding dav_hooks_binding;
  271. typedef struct dav_hooks_search dav_hooks_search;
  272.  
  273. /* ### deprecated name */
  274. typedef dav_hooks_propdb dav_hooks_db;
  275.  
  276.  
  277. /* --------------------------------------------------------------------
  278. **
  279. ** RESOURCE HANDLING
  280. */
  281.  
  282. /*
  283. ** Resource Types:
  284. ** The base protocol defines only file and collection resources.
  285. ** The versioning protocol defines several additional resource types
  286. ** to represent artifacts of a version control system.
  287. **
  288. ** This enumeration identifies the type of URL used to identify the
  289. ** resource. Since the same resource may have more than one type of
  290. ** URL which can identify it, dav_resource_type cannot be used
  291. ** alone to determine the type of the resource; attributes of the
  292. ** dav_resource object must also be consulted.
  293. */
  294. typedef enum {
  295.     DAV_RESOURCE_TYPE_UNKNOWN,
  296.  
  297.     DAV_RESOURCE_TYPE_REGULAR,          /* file or collection; could be
  298.                                          * unversioned, or version selector,
  299.                                          * or baseline selector */
  300.  
  301.     DAV_RESOURCE_TYPE_VERSION,          /* version or baseline URL */
  302.  
  303.     DAV_RESOURCE_TYPE_HISTORY,          /* version or baseline history URL */
  304.  
  305.     DAV_RESOURCE_TYPE_WORKING,          /* working resource URL */
  306.  
  307.     DAV_RESOURCE_TYPE_WORKSPACE,        /* workspace URL */
  308.  
  309.     DAV_RESOURCE_TYPE_ACTIVITY,         /* activity URL */
  310.  
  311.     DAV_RESOURCE_TYPE_PRIVATE           /* repository-private type */
  312.  
  313. } dav_resource_type;
  314.  
  315. /*
  316. ** Opaque, repository-specific information for a resource.
  317. */
  318. typedef struct dav_resource_private dav_resource_private;
  319.  
  320. /*
  321. ** Resource descriptor, generated by a repository provider.
  322. **
  323. ** Note: the lock-null state is not explicitly represented here,
  324. ** since it may be expensive to compute. Use dav_get_resource_state()
  325. ** to determine whether a non-existent resource is a lock-null resource.
  326. **
  327. ** A quick explanation of how the flags can apply to different resources:
  328. **
  329. ** unversioned file or collection:
  330. **     type       = DAV_RESOURCE_TYPE_REGULAR
  331. **     exists     = ? (1 if exists)
  332. **     collection = ? (1 if collection)
  333. **     versioned  = 0
  334. **     baselined  = 0
  335. **     working    = 0
  336. **
  337. ** version-controlled resource or configuration:
  338. **     type       = DAV_RESOURCE_TYPE_REGULAR
  339. **     exists     = 1
  340. **     collection = ? (1 if collection)
  341. **     versioned  = 1
  342. **     baselined  = ? (1 if configuration)
  343. **     working    = ? (1 if checked out)
  344. **
  345. ** version/baseline history:
  346. **     type       = DAV_RESOURCE_TYPE_HISTORY
  347. **     exists     = 1
  348. **     collection = 0
  349. **     versioned  = 0
  350. **     baselined  = 0
  351. **     working    = 0
  352. **
  353. ** version/baseline:
  354. **     type       = DAV_RESOURCE_TYPE_VERSION
  355. **     exists     = 1
  356. **     collection = ? (1 if collection)
  357. **     versioned  = 1
  358. **     baselined  = ? (1 if baseline)
  359. **     working    = 0
  360. **
  361. ** working resource:
  362. **     type       = DAV_RESOURCE_TYPE_WORKING
  363. **     exists     = 1
  364. **     collection = ? (1 if collection)
  365. **     versioned  = 1
  366. **     baselined  = 0
  367. **     working    = 1
  368. **
  369. ** workspace:
  370. **     type       = DAV_RESOURCE_TYPE_WORKSPACE
  371. **     exists     = ? (1 if exists)
  372. **     collection = 1
  373. **     versioned  = ? (1 if version-controlled)
  374. **     baselined  = ? (1 if baseline-controlled)
  375. **     working    = ? (1 if checked out)
  376. **
  377. ** activity:
  378. **     type       = DAV_RESOURCE_TYPE_ACTIVITY
  379. **     exists     = ? (1 if exists)
  380. **     collection = 0
  381. **     versioned  = 0
  382. **     baselined  = 0
  383. **     working    = 0
  384. */
  385. typedef struct dav_resource {
  386.     dav_resource_type type;
  387.  
  388.     int exists;         /* 0 => null resource */
  389.  
  390.     int collection;     /* 0 => file; can be 1 for
  391.                          * REGULAR, VERSION, and WORKING resources,
  392.                          * and is always 1 for WORKSPACE */
  393.  
  394.     int versioned;      /* 0 => unversioned; can be 1 for
  395.                          * REGULAR and WORKSPACE resources,
  396.                          * and is always 1 for VERSION and WORKING */
  397.  
  398.     int baselined;      /* 0 => not baselined; can be 1 for
  399.                          * REGULAR, VERSION, and WORKSPACE resources;
  400.                          * versioned == 1 when baselined == 1 */
  401.  
  402.     int working;        /* 0 => not checked out; can be 1 for
  403.                          * REGULAR and WORKSPACE resources,
  404.                          * and is always 1 for WORKING */
  405.  
  406.     const char *uri;    /* the URI for this resource */
  407.  
  408.     dav_resource_private *info;         /* the provider's private info */
  409.  
  410.     const dav_hooks_repository *hooks;  /* hooks used for this resource */
  411.  
  412.     /* When allocating items related specifically to this resource, the
  413.        following pool should be used. Its lifetime will be at least as
  414.        long as the dav_resource structure. */
  415.     apr_pool_t *pool;
  416.  
  417. } dav_resource;
  418.  
  419. /*
  420. ** Lock token type. Lock providers define the details of a lock token.
  421. ** However, all providers are expected to at least be able to parse
  422. ** the "opaquelocktoken" scheme, which is represented by a uuid_t.
  423. */
  424. typedef struct dav_locktoken dav_locktoken;
  425.  
  426.  
  427. /* --------------------------------------------------------------------
  428. **
  429. ** BUFFER HANDLING
  430. **
  431. ** These buffers are used as a lightweight buffer reuse mechanism. Apache
  432. ** provides sub-pool creation and destruction to much the same effect, but
  433. ** the sub-pools are a bit more general and heavyweight than these buffers.
  434. */
  435.  
  436. /* buffer for reuse; can grow to accomodate needed size */
  437. typedef struct
  438. {
  439.     apr_size_t alloc_len;       /* how much has been allocated */
  440.     apr_size_t cur_len;         /* how much is currently being used */
  441.     char *buf;                  /* buffer contents */
  442. } dav_buffer;
  443. #define DAV_BUFFER_MINSIZE      256    /* minimum size for buffer */
  444. #define DAV_BUFFER_PAD          64     /* amount of pad when growing */
  445.  
  446. /* set the cur_len to the given size and ensure space is available */
  447. DAV_DECLARE(void) dav_set_bufsize(apr_pool_t *p, dav_buffer *pbuf, 
  448.                                   apr_size_t size);
  449.  
  450. /* initialize a buffer and copy the specified (null-term'd) string into it */
  451. DAV_DECLARE(void) dav_buffer_init(apr_pool_t *p, dav_buffer *pbuf, 
  452.                                   const char *str);
  453.  
  454. /* check that the buffer can accomodate <extra_needed> more bytes */
  455. DAV_DECLARE(void) dav_check_bufsize(apr_pool_t *p, dav_buffer *pbuf, 
  456.                                     apr_size_t extra_needed);
  457.  
  458. /* append a string to the end of the buffer, adjust length */
  459. DAV_DECLARE(void) dav_buffer_append(apr_pool_t *p, dav_buffer *pbuf, 
  460.                                     const char *str);
  461.  
  462. /* place a string on the end of the buffer, do NOT adjust length */
  463. DAV_DECLARE(void) dav_buffer_place(apr_pool_t *p, dav_buffer *pbuf, 
  464.                                    const char *str);
  465.  
  466. /* place some memory on the end of a buffer; do NOT adjust length */
  467. DAV_DECLARE(void) dav_buffer_place_mem(apr_pool_t *p, dav_buffer *pbuf, 
  468.                                        const void *mem, apr_size_t amt, 
  469.                                        apr_size_t pad);
  470.  
  471.  
  472. /* --------------------------------------------------------------------
  473. **
  474. ** HANDY UTILITIES
  475. */
  476.  
  477. /* contains results from one of the getprop functions */
  478. typedef struct
  479. {
  480.     apr_text * propstats;       /* <propstat> element text */
  481.     apr_text * xmlns;           /* namespace decls for <response> elem */
  482. } dav_get_props_result;
  483.  
  484. /* holds the contents of a <response> element */
  485. typedef struct dav_response
  486. {
  487.     const char *href;           /* always */
  488.     const char *desc;           /* optional description at <response> level */
  489.  
  490.     /* use status if propresult.propstats is NULL. */
  491.     dav_get_props_result propresult;
  492.  
  493.     int status;
  494.  
  495.     struct dav_response *next;
  496. } dav_response;
  497.  
  498. typedef struct
  499. {
  500.     request_rec *rnew;          /* new subrequest */
  501.     dav_error err;              /* potential error response */
  502. } dav_lookup_result;
  503.  
  504.  
  505. dav_lookup_result dav_lookup_uri(const char *uri, request_rec *r,
  506.                                  int must_be_absolute);
  507.  
  508. /* defines type of property info a provider is to return */
  509. typedef enum {
  510.     DAV_PROP_INSERT_NOTDEF,     /* property is defined by this provider,
  511.                                    but nothing was inserted because the
  512.                                    (live) property is not defined for this
  513.                                    resource (it may be present as a dead
  514.                                    property). */
  515.     DAV_PROP_INSERT_NOTSUPP,    /* property is recognized by this provider,
  516.                                    but it is not supported, and cannot be
  517.                                    treated as a dead property */
  518.     DAV_PROP_INSERT_NAME,       /* a property name (empty elem) was
  519.                                    inserted into the text block */
  520.     DAV_PROP_INSERT_VALUE,      /* a property name/value pair was inserted
  521.                                    into the text block */
  522.     DAV_PROP_INSERT_SUPPORTED   /* a supported live property was added to
  523.                                    the text block as a
  524.                                    <DAV:supported-live-property> element */
  525. } dav_prop_insert;
  526.  
  527. /* ### this stuff is private to dav/fs/repos.c; move it... */
  528. /* format a time string (buf must be at least DAV_TIMEBUF_SIZE chars) */
  529. #define DAV_STYLE_ISO8601       1
  530. #define DAV_STYLE_RFC822        2
  531. #define DAV_TIMEBUF_SIZE        30
  532.  
  533. int dav_get_depth(request_rec *r, int def_depth);
  534.  
  535. int dav_validate_root(const apr_xml_doc *doc, const char *tagname);
  536. apr_xml_elem *dav_find_child(const apr_xml_elem *elem, const char *tagname);
  537.  
  538. /* gather up all the CDATA into a single string */
  539. DAV_DECLARE(const char *) dav_xml_get_cdata(const apr_xml_elem *elem, apr_pool_t *pool,
  540.                               int strip_white);
  541.  
  542. /*
  543. ** XML namespace handling
  544. **
  545. ** This structure tracks namespace declarations (xmlns:prefix="URI").
  546. ** It maintains a one-to-many relationship of URIs-to-prefixes. In other
  547. ** words, one URI may be defined by many prefixes, but any specific
  548. ** prefix will specify only one URI.
  549. **
  550. ** Prefixes using the "g###" pattern can be generated automatically if
  551. ** the caller does not have specific prefix requirements.
  552. */
  553. typedef struct {
  554.     apr_pool_t *pool;
  555.     apr_hash_t *uri_prefix;     /* map URIs to an available prefix */
  556.     apr_hash_t *prefix_uri;     /* map all prefixes to their URIs */
  557.     int count;                  /* counter for "g###" prefixes */
  558. } dav_xmlns_info;
  559.  
  560. /* create an empty dav_xmlns_info structure */
  561. DAV_DECLARE(dav_xmlns_info *) dav_xmlns_create(apr_pool_t *pool);
  562.  
  563. /* add a specific prefix/URI pair. the prefix/uri should have a lifetime
  564.    at least that of xmlns->pool */
  565. DAV_DECLARE(void) dav_xmlns_add(dav_xmlns_info *xi,
  566.                                 const char *prefix, const char *uri);
  567.  
  568. /* add a URI (if not present); any prefix is acceptable and is returned.
  569.    the uri should have a lifetime at least that xmlns->pool */
  570. DAV_DECLARE(const char *) dav_xmlns_add_uri(dav_xmlns_info *xi,
  571.                                             const char *uri);
  572.  
  573. /* return the URI for a specified prefix (or NULL if the prefix is unknown) */
  574. DAV_DECLARE(const char *) dav_xmlns_get_uri(dav_xmlns_info *xi,
  575.                                             const char *prefix);
  576.  
  577. /* return an available prefix for a specified URI (or NULL if the URI
  578.    is unknown) */
  579. DAV_DECLARE(const char *) dav_xmlns_get_prefix(dav_xmlns_info *xi,
  580.                                                const char *uri);
  581.  
  582. /* generate xmlns declarations (appending into the given text) */
  583. DAV_DECLARE(void) dav_xmlns_generate(dav_xmlns_info *xi,
  584.                                      apr_text_header *phdr);
  585.  
  586. /* --------------------------------------------------------------------
  587. **
  588. ** DAV PLUGINS
  589. */
  590.  
  591. /* ### docco ... */
  592.  
  593. /*
  594. ** dav_provider
  595. **
  596. ** This structure wraps up all of the hooks that a mod_dav provider can
  597. ** supply. The provider MUST supply <repos> and <propdb>. The rest are
  598. ** optional and should contain NULL if that feature is not supplied.
  599. **
  600. ** Note that a provider cannot pick and choose portions from various
  601. ** underlying implementations (which was theoretically possible in
  602. ** mod_dav 1.0). There are too many dependencies between a dav_resource
  603. ** (defined by <repos>) and the other functionality.
  604. **
  605. ** Live properties are not part of the dav_provider structure because they
  606. ** are handled through the APR_HOOK interface (to allow for multiple liveprop
  607. ** providers). The core always provides some properties, and then a given
  608. ** provider will add more properties.
  609. **
  610. ** Some providers may need to associate a context with the dav_provider
  611. ** structure -- the ctx field is available for storing this context. Just
  612. ** leave it NULL if it isn't required.
  613. */
  614. typedef struct {
  615.     const dav_hooks_repository *repos;
  616.     const dav_hooks_propdb *propdb;
  617.     const dav_hooks_locks *locks;
  618.     const dav_hooks_vsn *vsn;
  619.     const dav_hooks_binding *binding;
  620.     const dav_hooks_search *search;
  621.  
  622.     void *ctx;
  623. } dav_provider;
  624.  
  625. /*
  626. ** gather_propsets: gather all live property propset-URIs
  627. **
  628. ** The hook implementor should push one or more URIs into the specified
  629. ** array. These URIs are returned in the DAV: header to let clients know
  630. ** what sets of live properties are supported by the installation. mod_dav
  631. ** will place open/close angle brackets around each value (much like
  632. ** a Coded-URL); quotes and brackets should not be in the value.
  633. **
  634. ** Example:    http://apache.org/dav/props/
  635. **
  636. ** (of course, use your own domain to ensure a unique value)
  637. */
  638. APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, gather_propsets, 
  639.                          (apr_array_header_t *uris))
  640.  
  641. /*
  642. ** find_liveprop: find a live property, returning a non-zero, unique,
  643. **                opaque identifier.
  644. **
  645. ** If the hook implementor determines the specified URI/name refers to
  646. ** one of its properties, then it should fill in HOOKS and return a
  647. ** non-zero value. The returned value is the "property ID" and will
  648. ** be passed to the various liveprop hook functions.
  649. **
  650. ** Return 0 if the property is not defined by the hook implementor.
  651. */
  652. APR_DECLARE_EXTERNAL_HOOK(dav, DAV, int, find_liveprop,
  653.                          (const dav_resource *resource,
  654.                           const char *ns_uri, const char *name,
  655.                           const dav_hooks_liveprop **hooks))
  656.  
  657. /*
  658. ** insert_all_liveprops: insert all (known) live property names/values.
  659. **
  660. ** The hook implementor should append XML text to PHDR, containing liveprop
  661. ** names. If INSVALUE is true, then the property values should also be
  662. ** inserted into the output XML stream.
  663. **
  664. ** The liveprop provider should insert *all* known and *defined* live
  665. ** properties on the specified resource. If a particular liveprop is
  666. ** not defined for this resource, then it should not be inserted.
  667. */
  668. APR_DECLARE_EXTERNAL_HOOK(dav, DAV, void, insert_all_liveprops, 
  669.                          (request_rec *r, const dav_resource *resource,
  670.                           dav_prop_insert what, apr_text_header *phdr))
  671.  
  672. const dav_hooks_locks *dav_get_lock_hooks(request_rec *r);
  673. const dav_hooks_propdb *dav_get_propdb_hooks(request_rec *r);
  674. const dav_hooks_vsn *dav_get_vsn_hooks(request_rec *r);
  675. const dav_hooks_binding *dav_get_binding_hooks(request_rec *r);
  676. const dav_hooks_search *dav_get_search_hooks(request_rec *r);
  677.  
  678. DAV_DECLARE(void) dav_register_provider(apr_pool_t *p, const char *name,
  679.                                         const dav_provider *hooks);
  680. const dav_provider * dav_lookup_provider(const char *name);
  681.  
  682.  
  683. /* ### deprecated */
  684. #define DAV_GET_HOOKS_PROPDB(r)         dav_get_propdb_hooks(r)
  685. #define DAV_GET_HOOKS_LOCKS(r)          dav_get_lock_hooks(r)
  686. #define DAV_GET_HOOKS_VSN(r)            dav_get_vsn_hooks(r)
  687. #define DAV_GET_HOOKS_BINDING(r)        dav_get_binding_hooks(r)
  688. #define DAV_GET_HOOKS_SEARCH(r)         dav_get_search_hooks(r)
  689.  
  690.  
  691. /* --------------------------------------------------------------------
  692. **
  693. ** IF HEADER PROCESSING
  694. **
  695. ** Here is the definition of the If: header from RFC 2518, S9.4:
  696. **
  697. **    If = "If" ":" (1*No-tag-list | 1*Tagged-list)
  698. **    No-tag-list = List
  699. **    Tagged-list = Resource 1*List
  700. **    Resource = Coded-URL
  701. **    List = "(" 1*(["Not"](State-token | "[" entity-tag "]")) ")"
  702. **    State-token = Coded-URL
  703. **    Coded-URL = "<" absoluteURI ">"        ; absoluteURI from RFC 2616
  704. **
  705. ** List corresponds to dav_if_state_list. No-tag-list corresponds to
  706. ** dav_if_header with uri==NULL. Tagged-list corresponds to a sequence of
  707. ** dav_if_header structures with (duplicate) uri==Resource -- one
  708. ** dav_if_header per state_list. A second Tagged-list will start a new
  709. ** sequence of dav_if_header structures with the new URI.
  710. **
  711. ** A summary of the semantics, mapped into our structures:
  712. **    - Chained dav_if_headers: OR
  713. **    - Chained dav_if_state_lists: AND
  714. **    - NULL uri matches all resources
  715. */
  716.  
  717. typedef enum
  718. {
  719.     dav_if_etag,
  720.     dav_if_opaquelock
  721. } dav_if_state_type;
  722.  
  723. typedef struct dav_if_state_list
  724. {
  725.     dav_if_state_type type;
  726.  
  727.     int condition;
  728. #define DAV_IF_COND_NORMAL      0
  729. #define DAV_IF_COND_NOT         1    /* "Not" was applied */
  730.  
  731.     const char *etag;
  732.     dav_locktoken *locktoken;
  733.  
  734.     struct dav_if_state_list *next;
  735. } dav_if_state_list;
  736.  
  737. typedef struct dav_if_header
  738. {
  739.     const char *uri;
  740.     apr_size_t uri_len;
  741.     struct dav_if_state_list *state;
  742.     struct dav_if_header *next;
  743.  
  744.     int dummy_header;   /* used internally by the lock/etag validation */
  745. } dav_if_header;
  746.  
  747. typedef struct dav_locktoken_list 
  748. {
  749.     dav_locktoken *locktoken;
  750.     struct dav_locktoken_list *next;
  751. } dav_locktoken_list;
  752.  
  753. dav_error * dav_get_locktoken_list(request_rec *r, dav_locktoken_list **ltl);
  754.  
  755.  
  756. /* --------------------------------------------------------------------
  757. **
  758. ** LIVE PROPERTY HANDLING
  759. */
  760.  
  761. /* opaque type for PROPPATCH rollback information */
  762. typedef struct dav_liveprop_rollback dav_liveprop_rollback;
  763.  
  764. struct dav_hooks_liveprop
  765. {
  766.     /*
  767.     ** Insert property information into a text block. The property to
  768.     ** insert is identified by the propid value. The information to insert
  769.     ** is identified by the "what" argument, as follows:
  770.     **   DAV_PROP_INSERT_NAME
  771.     **      property name, as an empty XML element
  772.     **   DAV_PROP_INSERT_VALUE
  773.     **      property name/value, as an XML element
  774.     **   DAV_PROP_INSERT_SUPPORTED
  775.     **      if the property is defined on the resource, then
  776.     **      a DAV:supported-live-property element, as defined
  777.     **      by the DeltaV extensions to RFC2518.
  778.     **                      
  779.     ** Providers should return DAV_PROP_INSERT_NOTDEF if the property is
  780.     ** known and not defined for this resource, so should be handled as a
  781.     ** dead property. If a provider recognizes, but does not support, a
  782.     ** property, and does not want it handled as a dead property, it should
  783.     ** return DAV_PROP_INSERT_NOTSUPP.
  784.     **
  785.     ** Returns one of DAV_PROP_INSERT_* based on what happened.
  786.     **
  787.     ** ### we may need more context... ie. the lock database
  788.     */
  789.     dav_prop_insert (*insert_prop)(const dav_resource *resource,
  790.                                    int propid, dav_prop_insert what,
  791.                                    apr_text_header *phdr);
  792.  
  793.     /*
  794.     ** Determine whether a given property is writable.
  795.     **
  796.     ** ### we may want a different semantic. i.e. maybe it should be
  797.     ** ### "can we write <value> into this property?"
  798.     **
  799.     ** Returns 1 if the live property can be written, 0 if read-only.
  800.     */
  801.     int (*is_writable)(const dav_resource *resource, int propid);
  802.  
  803.     /*
  804.     ** This member defines the set of namespace URIs that the provider
  805.     ** uses for its properties. When insert_all is called, it will be
  806.     ** passed a list of integers that map from indices into this list
  807.     ** to namespace IDs for output generation.
  808.     **
  809.     ** The last entry in this list should be a NULL value (sentinel).
  810.     */
  811.     const char * const * namespace_uris;
  812.  
  813.     /*
  814.     ** ### this is not the final design. we want an open-ended way for
  815.     ** ### liveprop providers to attach *new* properties. To this end,
  816.     ** ### we'll have a "give me a list of the props you define", a way
  817.     ** ### to check for a prop's existence, a way to validate a set/remove
  818.     ** ### of a prop, and a way to execute/commit/rollback that change.
  819.     */
  820.  
  821.     /*
  822.     ** Validate that the live property can be assigned a value, and that
  823.     ** the provided value is valid.
  824.     **
  825.     ** elem will point to the XML element that names the property. For
  826.     ** example:
  827.     **     <lp1:executable>T</lp1:executable>
  828.     **
  829.     ** The provider can access the cdata fields and the child elements
  830.     ** to extract the relevant pieces.
  831.     **
  832.     ** operation is one of DAV_PROP_OP_SET or _DELETE.
  833.     **
  834.     ** The provider may return a value in *context which will be passed
  835.     ** to each of the exec/commit/rollback functions. For example, this
  836.     ** may contain an internal value which has been processed from the
  837.     ** input element.
  838.     **
  839.     ** The provider must set defer_to_dead to true (non-zero) or false.
  840.     ** If true, then the set/remove is deferred to the dead property
  841.     ** database. Note: it will be set to zero on entry.
  842.     */
  843.     dav_error * (*patch_validate)(const dav_resource *resource,
  844.                                   const apr_xml_elem *elem,
  845.                                   int operation,
  846.                                   void **context,
  847.                                   int *defer_to_dead);
  848.  
  849.     /* ### doc... */
  850.     dav_error * (*patch_exec)(const dav_resource *resource,
  851.                               const apr_xml_elem *elem,
  852.                               int operation,
  853.                               void *context,
  854.                               dav_liveprop_rollback **rollback_ctx);
  855.  
  856.     /* ### doc... */
  857.     void (*patch_commit)(const dav_resource *resource,
  858.                          int operation,
  859.                          void *context,
  860.                          dav_liveprop_rollback *rollback_ctx);
  861.  
  862.     /* ### doc... */
  863.     dav_error * (*patch_rollback)(const dav_resource *resource,
  864.                                   int operation,
  865.                                   void *context,
  866.                                   dav_liveprop_rollback *rollback_ctx);
  867.  
  868.     /*
  869.     ** If a provider needs a context to associate with this hooks structure,
  870.     ** then this field may be used. In most cases, it will just be NULL.
  871.     */
  872.     void *ctx;
  873. };
  874.  
  875. /*
  876. ** dav_liveprop_spec: specify a live property
  877. **
  878. ** This structure is used as a standard way to determine if a particular
  879. ** property is a live property. Its use is not part of the mandated liveprop
  880. ** interface, but can be used by liveprop providers in conjuction with the
  881. ** utility routines below.
  882. **
  883. ** spec->name == NULL is the defined end-sentinel for a list of specs.
  884. */
  885. typedef struct {
  886.     int ns;             /* provider-local namespace index */
  887.     const char *name;   /* name of the property */
  888.  
  889.     int propid;         /* provider-local property ID */
  890.  
  891.     int is_writable;    /* is the property writable? */
  892.  
  893. } dav_liveprop_spec;
  894.  
  895. /*
  896. ** dav_liveprop_group: specify a group of liveprops
  897. **
  898. ** This structure specifies a group of live properties, their namespaces,
  899. ** and how to handle them.
  900. */
  901. typedef struct {
  902.     const dav_liveprop_spec *specs;
  903.     const char * const *namespace_uris;
  904.     const dav_hooks_liveprop *hooks;
  905.  
  906. } dav_liveprop_group;
  907.  
  908. /* ### docco */
  909. DAV_DECLARE(int) dav_do_find_liveprop(const char *ns_uri, const char *name,
  910.                                       const dav_liveprop_group *group,
  911.                                       const dav_hooks_liveprop **hooks);
  912.  
  913. /* ### docco */
  914. DAV_DECLARE(int) dav_get_liveprop_info(int propid,
  915.                                        const dav_liveprop_group *group,
  916.                                        const dav_liveprop_spec **info);
  917.  
  918. /* ### docco */
  919. DAV_DECLARE(void) dav_register_liveprop_group(apr_pool_t *pool, 
  920.                                               const dav_liveprop_group *group);
  921.  
  922. /* ### docco */
  923. DAV_DECLARE(int) dav_get_liveprop_ns_index(const char *uri);
  924.  
  925. /* ### docco */
  926. int dav_get_liveprop_ns_count(void);
  927.  
  928. /* ### docco */
  929. void dav_add_all_liveprop_xmlns(apr_pool_t *p, apr_text_header *phdr);
  930.  
  931. /*
  932. ** The following three functions are part of mod_dav's internal handling
  933. ** for the core WebDAV properties. They are not part of mod_dav's API.
  934. */
  935. int dav_core_find_liveprop(const dav_resource *resource,
  936.                            const char *ns_uri, const char *name,
  937.                            const dav_hooks_liveprop **hooks);
  938. void dav_core_insert_all_liveprops(request_rec *r,
  939.                                    const dav_resource *resource,
  940.                                    dav_prop_insert what, apr_text_header *phdr);
  941. void dav_core_register_uris(apr_pool_t *p);
  942.  
  943.  
  944. /*
  945. ** Standard WebDAV Property Identifiers
  946. **
  947. ** A live property provider does not need to use these; they are simply
  948. ** provided for convenience.
  949. **
  950. ** Property identifiers need to be unique within a given provider, but not
  951. ** *across* providers (note: this uniqueness constraint was different in
  952. ** older versions of mod_dav).
  953. **
  954. ** The identifiers start at 20000 to make it easier for providers to avoid
  955. ** conflicts with the standard properties. The properties are arranged
  956. ** alphabetically, and may be reordered from time to time (as properties
  957. ** are introduced).
  958. **
  959. ** NOTE: there is no problem with reordering (e.g. binary compat) since the
  960. ** identifiers are only used within a given provider, which would pick up
  961. ** the entire set of changes upon a recompile.
  962. */
  963. enum {
  964.     DAV_PROPID_BEGIN = 20000,
  965.  
  966.     /* Standard WebDAV properties (RFC 2518) */
  967.     DAV_PROPID_creationdate,
  968.     DAV_PROPID_displayname,
  969.     DAV_PROPID_getcontentlanguage,
  970.     DAV_PROPID_getcontentlength,
  971.     DAV_PROPID_getcontenttype,
  972.     DAV_PROPID_getetag,
  973.     DAV_PROPID_getlastmodified,
  974.     DAV_PROPID_lockdiscovery,
  975.     DAV_PROPID_resourcetype,
  976.     DAV_PROPID_source,
  977.     DAV_PROPID_supportedlock,
  978.  
  979.     /* DeltaV properties (from the I-D (#14)) */
  980.     DAV_PROPID_activity_checkout_set,
  981.     DAV_PROPID_activity_set,
  982.     DAV_PROPID_activity_version_set,
  983.     DAV_PROPID_auto_merge_set,
  984.     DAV_PROPID_auto_version,
  985.     DAV_PROPID_baseline_collection,
  986.     DAV_PROPID_baseline_controlled_collection,
  987.     DAV_PROPID_baseline_controlled_collection_set,
  988.     DAV_PROPID_checked_in,
  989.     DAV_PROPID_checked_out,
  990.     DAV_PROPID_checkin_fork,
  991.     DAV_PROPID_checkout_fork,
  992.     DAV_PROPID_checkout_set,
  993.     DAV_PROPID_comment,
  994.     DAV_PROPID_creator_displayname,
  995.     DAV_PROPID_current_activity_set,
  996.     DAV_PROPID_current_workspace_set,
  997.     DAV_PROPID_default_variant,
  998.     DAV_PROPID_eclipsed_set,
  999.     DAV_PROPID_label_name_set,
  1000.     DAV_PROPID_merge_set,
  1001.     DAV_PROPID_precursor_set,
  1002.     DAV_PROPID_predecessor_set,
  1003.     DAV_PROPID_root_version,
  1004.     DAV_PROPID_subactivity_set,
  1005.     DAV_PROPID_subbaseline_set,
  1006.     DAV_PROPID_successor_set,
  1007.     DAV_PROPID_supported_method_set,
  1008.     DAV_PROPID_supported_live_property_set,
  1009.     DAV_PROPID_supported_report_set,
  1010.     DAV_PROPID_unreserved,
  1011.     DAV_PROPID_variant_set,
  1012.     DAV_PROPID_version_controlled_binding_set,
  1013.     DAV_PROPID_version_controlled_configuration,
  1014.     DAV_PROPID_version_history,
  1015.     DAV_PROPID_version_name,
  1016.     DAV_PROPID_workspace,
  1017.     DAV_PROPID_workspace_checkout_set,
  1018.  
  1019.     DAV_PROPID_END
  1020. };
  1021.  
  1022. /*
  1023. ** Property Identifier Registration
  1024. **
  1025. ** At the moment, mod_dav requires live property providers to ensure that
  1026. ** each property returned has a unique value. For now, this is done through
  1027. ** central registration (there are no known providers other than the default,
  1028. ** so this remains manageable).
  1029. **
  1030. ** WARNING: the TEST ranges should never be "shipped".
  1031. */
  1032. #define DAV_PROPID_CORE         10000   /* ..10099. defined by mod_dav */
  1033. #define DAV_PROPID_FS           10100   /* ..10299.
  1034.                                            mod_dav filesystem provider. */
  1035. #define DAV_PROPID_TEST1        10300   /* ..10399 */
  1036. #define DAV_PROPID_TEST2        10400   /* ..10499 */
  1037. #define DAV_PROPID_TEST3        10500   /* ..10599 */
  1038. /* Next: 10600 */
  1039.  
  1040.  
  1041. /* --------------------------------------------------------------------
  1042. **
  1043. ** DATABASE FUNCTIONS
  1044. */
  1045.  
  1046. typedef struct dav_db dav_db;
  1047. typedef struct dav_namespace_map dav_namespace_map;
  1048. typedef struct dav_deadprop_rollback dav_deadprop_rollback;
  1049.  
  1050. typedef struct {
  1051.     const char *ns;     /* "" signals "no namespace" */
  1052.     const char *name;
  1053. } dav_prop_name;
  1054.  
  1055. /* hook functions to enable pluggable databases */
  1056. struct dav_hooks_propdb
  1057. {
  1058.     dav_error * (*open)(apr_pool_t *p, const dav_resource *resource, int ro,
  1059.                         dav_db **pdb);
  1060.     void (*close)(dav_db *db);
  1061.  
  1062.     /*
  1063.     ** In bulk, define any namespaces that the values and their name
  1064.     ** elements may need.
  1065.     **
  1066.     ** Note: sometimes mod_dav will defer calling this until output_value
  1067.     ** returns found==1. If the output process needs the dav_xmlns_info
  1068.     ** filled for its work, then it will need to fill it on demand rather
  1069.     ** than depending upon this hook to fill in the structure.
  1070.     **
  1071.     ** Note: this will *always* be called during an output sequence. Thus,
  1072.     ** the provider may rely solely on using this to fill the xmlns info.
  1073.     */
  1074.     dav_error * (*define_namespaces)(dav_db *db, dav_xmlns_info *xi);
  1075.  
  1076.     /*
  1077.     ** Output the value from the database (i.e. add an element name and
  1078.     ** the value into *phdr). Set *found based on whether the name/value
  1079.     ** was found in the propdb.
  1080.     **
  1081.     ** Note: it is NOT an error for the key/value pair to not exist.
  1082.     **
  1083.     ** The dav_xmlns_info passed to define_namespaces() is also passed to
  1084.     ** each output_value() call so that namespaces can be added on-demand.
  1085.     ** It can also be used to look up prefixes or URIs during the output
  1086.     ** process.
  1087.     */
  1088.     dav_error * (*output_value)(dav_db *db, const dav_prop_name *name,
  1089.                                 dav_xmlns_info *xi,
  1090.                                 apr_text_header *phdr, int *found);
  1091.  
  1092.     /*
  1093.     ** Build a mapping from "global" namespaces (stored in apr_xml_*)
  1094.     ** into provider-local namespace identifiers.
  1095.     **
  1096.     ** This mapping should be done once per set of namespaces, and the
  1097.     ** resulting mapping should be passed into the store() hook function.
  1098.     **
  1099.     ** Note: usually, there is just a single document/namespaces for all
  1100.     ** elements passed. However, the generality of creating multiple
  1101.     ** mappings and passing them to store() is provided here.
  1102.     **
  1103.     ** Note: this is only in preparation for a series of store() calls.
  1104.     ** As a result, the propdb must be open for read/write access when
  1105.     ** this function is called.
  1106.     */
  1107.     dav_error * (*map_namespaces)(dav_db *db,
  1108.                                   const apr_array_header_t *namespaces,
  1109.                                   dav_namespace_map **mapping);
  1110.     
  1111.     /*
  1112.     ** Store a property value for a given name. The value->combined field
  1113.     ** MUST be set for this call.
  1114.     **
  1115.     ** ### WARNING: current providers will quote the text within ELEM.
  1116.     ** ### this implies you can call this function only once with a given
  1117.     ** ### element structure (a second time will quote it again).
  1118.     */
  1119.     dav_error * (*store)(dav_db *db, const dav_prop_name *name,
  1120.                          const apr_xml_elem *elem,
  1121.                          dav_namespace_map *mapping);
  1122.  
  1123.     /* remove a given property */
  1124.     dav_error * (*remove)(dav_db *db, const dav_prop_name *name);
  1125.  
  1126.     /* returns 1 if the record specified by "key" exists; 0 otherwise */
  1127.     int (*exists)(dav_db *db, const dav_prop_name *name);
  1128.  
  1129.     /*
  1130.     ** Iterate over the property names in the database.
  1131.     **
  1132.     ** iter->name.ns == iter->name.name == NULL when there are no more names.
  1133.     **
  1134.     ** Note: only one iteration may occur over the propdb at a time.
  1135.     */
  1136.     dav_error * (*first_name)(dav_db *db, dav_prop_name *pname);
  1137.     dav_error * (*next_name)(dav_db *db, dav_prop_name *pname);
  1138.  
  1139.     /*
  1140.     ** Rollback support: get rollback context, and apply it.
  1141.     **
  1142.     ** struct dav_deadprop_rollback is a provider-private structure; it
  1143.     ** should remember the name, and the name's old value (or the fact that
  1144.     ** the value was not present, and should be deleted if a rollback occurs).
  1145.     */
  1146.     dav_error * (*get_rollback)(dav_db *db, const dav_prop_name *name,
  1147.                                 dav_deadprop_rollback **prollback);
  1148.     dav_error * (*apply_rollback)(dav_db *db,
  1149.                                   dav_deadprop_rollback *rollback);
  1150.  
  1151.     /*
  1152.     ** If a provider needs a context to associate with this hooks structure,
  1153.     ** then this field may be used. In most cases, it will just be NULL.
  1154.     */
  1155.     void *ctx;
  1156. };
  1157.  
  1158.  
  1159. /* --------------------------------------------------------------------
  1160. **
  1161. ** LOCK FUNCTIONS
  1162. */
  1163.  
  1164. /* Used to represent a Timeout header of "Infinity" */
  1165. #define DAV_TIMEOUT_INFINITE 0
  1166.  
  1167. time_t dav_get_timeout(request_rec *r);
  1168.  
  1169. /*
  1170. ** Opaque, provider-specific information for a lock database.
  1171. */
  1172. typedef struct dav_lockdb_private dav_lockdb_private;
  1173.  
  1174. /*
  1175. ** Opaque, provider-specific information for a lock record.
  1176. */
  1177. typedef struct dav_lock_private dav_lock_private;
  1178.  
  1179. /*
  1180. ** Lock database type. Lock providers are urged to implement a "lazy" open, so
  1181. ** doing an "open" is cheap until something is actually needed from the DB.
  1182. */
  1183. typedef struct
  1184. {
  1185.     const dav_hooks_locks *hooks;   /* the hooks used for this lockdb */
  1186.     int ro;                         /* was it opened readonly? */
  1187.  
  1188.     dav_lockdb_private *info;
  1189.  
  1190. } dav_lockdb;
  1191.  
  1192. typedef enum {
  1193.     DAV_LOCKSCOPE_UNKNOWN,
  1194.     DAV_LOCKSCOPE_EXCLUSIVE,
  1195.     DAV_LOCKSCOPE_SHARED
  1196. } dav_lock_scope;
  1197.  
  1198. typedef enum {
  1199.     DAV_LOCKTYPE_UNKNOWN,
  1200.     DAV_LOCKTYPE_WRITE
  1201. } dav_lock_type;
  1202.  
  1203. typedef enum {
  1204.     DAV_LOCKREC_DIRECT,             /* lock asserted on this resource */
  1205.     DAV_LOCKREC_INDIRECT,           /* lock inherited from a parent */
  1206.     DAV_LOCKREC_INDIRECT_PARTIAL    /* most info is not filled in */
  1207. } dav_lock_rectype;
  1208.  
  1209. /*
  1210. ** dav_lock: hold information about a lock on a resource.
  1211. **
  1212. ** This structure is used for both direct and indirect locks. A direct lock
  1213. ** is a lock applied to a specific resource by the client. An indirect lock
  1214. ** is one that is inherited from a parent resource by virtue of a non-zero
  1215. ** Depth: header when the lock was applied.
  1216. **
  1217. ** mod_dav records both types of locks in the lock database, managing their
  1218. ** addition/removal as resources are moved about the namespace.
  1219. **
  1220. ** Note that the lockdb is free to marshal this structure in any form that
  1221. ** it likes.
  1222. **
  1223. ** For a "partial" lock, the <rectype> and <locktoken> fields must be filled
  1224. ** in. All other (user) fields should be zeroed. The lock provider will
  1225. ** usually fill in the <info> field, and the <next> field may be used to
  1226. ** construct a list of partial locks.
  1227. **
  1228. ** The lock provider MUST use the info field to store a value such that a
  1229. ** dav_lock structure can locate itself in the underlying lock database.
  1230. ** This requirement is needed for refreshing: when an indirect dav_lock is
  1231. ** refreshed, its reference to the direct lock does not specify the direct's
  1232. ** resource, so the only way to locate the (refreshed, direct) lock in the
  1233. ** database is to use the info field.
  1234. **
  1235. ** Note that <is_locknull> only refers to the resource where this lock was
  1236. ** found.
  1237. ** ### hrm. that says the abstraction is wrong. is_locknull may disappear.
  1238. */
  1239. typedef struct dav_lock
  1240. {
  1241.     dav_lock_rectype rectype;   /* type of lock record */
  1242.     int is_locknull;            /* lock establishes a locknull resource */
  1243.  
  1244.     /* ### put the resource in here? */
  1245.  
  1246.     dav_lock_scope scope;       /* scope of the lock */
  1247.     dav_lock_type type;         /* type of lock */
  1248.     int depth;                  /* depth of the lock */
  1249.     time_t timeout;             /* when the lock will timeout */
  1250.  
  1251.     const dav_locktoken *locktoken;  /* the token that was issued */
  1252.  
  1253.     const char *owner;          /* (XML) owner of the lock */
  1254.     const char *auth_user;      /* auth'd username owning lock */
  1255.  
  1256.     dav_lock_private *info;     /* private to the lockdb */
  1257.  
  1258.     struct dav_lock *next;      /* for managing a list of locks */
  1259. } dav_lock;
  1260.  
  1261. /* Property-related public lock functions */
  1262. const char *dav_lock_get_activelock(request_rec *r, dav_lock *locks,
  1263.                                     dav_buffer *pbuf);
  1264.  
  1265. /* LockDB-related public lock functions */
  1266. dav_error * dav_lock_parse_lockinfo(request_rec *r,
  1267.                                     const dav_resource *resrouce,
  1268.                                     dav_lockdb *lockdb,
  1269.                                     const apr_xml_doc *doc,
  1270.                                     dav_lock **lock_request);
  1271. int dav_unlock(request_rec *r, const dav_resource *resource,
  1272.                const dav_locktoken *locktoken);
  1273. dav_error * dav_add_lock(request_rec *r, const dav_resource *resource,
  1274.                          dav_lockdb *lockdb, dav_lock *request,
  1275.                          dav_response **response);
  1276. dav_error * dav_notify_created(request_rec *r,
  1277.                                dav_lockdb *lockdb,
  1278.                                const dav_resource *resource,
  1279.                                int resource_state,
  1280.                                int depth);
  1281.  
  1282. DAV_DECLARE(dav_error*) dav_lock_query(dav_lockdb *lockdb, 
  1283.                                        const dav_resource *resource,
  1284.                                        dav_lock **locks);
  1285.  
  1286. dav_error * dav_validate_request(request_rec *r, dav_resource *resource,
  1287.                                  int depth, dav_locktoken *locktoken,
  1288.                                  dav_response **response, int flags,
  1289.                                  dav_lockdb *lockdb);
  1290. /*
  1291. ** flags:
  1292. **    0x0F -- reserved for <dav_lock_scope> values
  1293. **
  1294. **    other flags, detailed below
  1295. */
  1296. #define DAV_VALIDATE_RESOURCE   0x0010  /* validate just the resource */
  1297. #define DAV_VALIDATE_PARENT     0x0020  /* validate resource AND its parent */
  1298. #define DAV_VALIDATE_ADD_LD     0x0040  /* add DAV:lockdiscovery into
  1299.                                            the 424 DAV:response */
  1300. #define DAV_VALIDATE_USE_424    0x0080  /* return 424 status, not 207 */
  1301. #define DAV_VALIDATE_IS_PARENT  0x0100  /* for internal use */
  1302.  
  1303. /* Lock-null related public lock functions */
  1304. int dav_get_resource_state(request_rec *r, const dav_resource *resource);
  1305.  
  1306. /* Lock provider hooks. Locking is optional, so there may be no
  1307.  * lock provider for a given repository.
  1308.  */
  1309. struct dav_hooks_locks
  1310. {
  1311.     /* Return the supportedlock property for a resource */
  1312.     const char * (*get_supportedlock)(
  1313.         const dav_resource *resource
  1314.     );
  1315.  
  1316.     /* Parse a lock token URI, returning a lock token object allocated
  1317.      * in the given pool.
  1318.      */
  1319.     dav_error * (*parse_locktoken)(
  1320.         apr_pool_t *p,
  1321.         const char *char_token,
  1322.         dav_locktoken **locktoken_p
  1323.     );
  1324.  
  1325.     /* Format a lock token object into a URI string, allocated in
  1326.      * the given pool.
  1327.      *
  1328.      * Always returns non-NULL.
  1329.      */
  1330.     const char * (*format_locktoken)(
  1331.         apr_pool_t *p,
  1332.         const dav_locktoken *locktoken
  1333.     );
  1334.  
  1335.     /* Compare two lock tokens.
  1336.      *
  1337.      * Result < 0  => lt1 < lt2
  1338.      * Result == 0 => lt1 == lt2
  1339.      * Result > 0  => lt1 > lt2
  1340.      */
  1341.     int (*compare_locktoken)(
  1342.         const dav_locktoken *lt1,
  1343.         const dav_locktoken *lt2
  1344.     );
  1345.  
  1346.     /* Open the provider's lock database.
  1347.      *
  1348.      * The provider may or may not use a "real" database for locks
  1349.      * (a lock could be an attribute on a resource, for example).
  1350.      *
  1351.      * The provider may choose to use the value of the DAVLockDB directive
  1352.      * (as returned by dav_get_lockdb_path()) to decide where to place
  1353.      * any storage it may need.
  1354.      *
  1355.      * The request storage pool should be associated with the lockdb,
  1356.      * so it can be used in subsequent operations.
  1357.      *
  1358.      * If ro != 0, only readonly operations will be performed.
  1359.      * If force == 0, the open can be "lazy"; no subsequent locking operations
  1360.      * may occur.
  1361.      * If force != 0, locking operations will definitely occur.
  1362.      */
  1363.     dav_error * (*open_lockdb)(
  1364.         request_rec *r,
  1365.         int ro,
  1366.         int force,
  1367.         dav_lockdb **lockdb
  1368.     );
  1369.  
  1370.     /* Indicates completion of locking operations */
  1371.     void (*close_lockdb)(
  1372.         dav_lockdb *lockdb
  1373.     );
  1374.  
  1375.     /* Take a resource out of the lock-null state. */
  1376.     dav_error * (*remove_locknull_state)(
  1377.         dav_lockdb *lockdb,
  1378.         const dav_resource *resource
  1379.     );
  1380.  
  1381.     /*
  1382.     ** Create a (direct) lock structure for the given resource. A locktoken
  1383.     ** will be created.
  1384.     **
  1385.     ** The lock provider may store private information into lock->info.
  1386.     */
  1387.     dav_error * (*create_lock)(dav_lockdb *lockdb,
  1388.                                const dav_resource *resource,
  1389.                                dav_lock **lock);
  1390.  
  1391.     /*
  1392.     ** Get the locks associated with the specified resource.
  1393.     **
  1394.     ** If resolve_locks is true (non-zero), then any indirect locks are
  1395.     ** resolved to their actual, direct lock (i.e. the reference to followed
  1396.     ** to the original lock).
  1397.     **
  1398.     ** The locks, if any, are returned as a linked list in no particular
  1399.     ** order. If no locks are present, then *locks will be NULL.
  1400.     */
  1401.     dav_error * (*get_locks)(dav_lockdb *lockdb,
  1402.                              const dav_resource *resource,
  1403.                              int calltype,
  1404.                              dav_lock **locks);
  1405.  
  1406. #define DAV_GETLOCKS_RESOLVED   0    /* resolve indirects to directs */
  1407. #define DAV_GETLOCKS_PARTIAL    1    /* leave indirects partially filled */
  1408. #define DAV_GETLOCKS_COMPLETE   2    /* fill out indirect locks */
  1409.  
  1410.     /*
  1411.     ** Find a particular lock on a resource (specified by its locktoken).
  1412.     **
  1413.     ** *lock will be set to NULL if the lock is not found.
  1414.     **
  1415.     ** Note that the provider can optimize the unmarshalling -- only one
  1416.     ** lock (or none) must be constructed and returned.
  1417.     **
  1418.     ** If partial_ok is true (non-zero), then an indirect lock can be
  1419.     ** partially filled in. Otherwise, another lookup is done and the
  1420.     ** lock structure will be filled out as a DAV_LOCKREC_INDIRECT.
  1421.     */
  1422.     dav_error * (*find_lock)(dav_lockdb *lockdb,
  1423.                              const dav_resource *resource,
  1424.                              const dav_locktoken *locktoken,
  1425.                              int partial_ok,
  1426.                              dav_lock **lock);
  1427.  
  1428.     /*
  1429.     ** Quick test to see if the resource has *any* locks on it.
  1430.     **
  1431.     ** This is typically used to determine if a non-existent resource
  1432.     ** has a lock and is (therefore) a locknull resource.
  1433.     **
  1434.     ** WARNING: this function may return TRUE even when timed-out locks
  1435.     **          exist (i.e. it may not perform timeout checks).
  1436.     */
  1437.     dav_error * (*has_locks)(dav_lockdb *lockdb,
  1438.                              const dav_resource *resource,
  1439.                              int *locks_present);
  1440.  
  1441.     /*
  1442.     ** Append the specified lock(s) to the set of locks on this resource.
  1443.     **
  1444.     ** If "make_indirect" is true (non-zero), then the specified lock(s)
  1445.     ** should be converted to an indirect lock (if it is a direct lock)
  1446.     ** before appending. Note that the conversion to an indirect lock does
  1447.     ** not alter the passed-in lock -- the change is internal the
  1448.     ** append_locks function.
  1449.     **
  1450.     ** Multiple locks are specified using the lock->next links.
  1451.     */
  1452.     dav_error * (*append_locks)(dav_lockdb *lockdb,
  1453.                                 const dav_resource *resource,
  1454.                                 int make_indirect,
  1455.                                 const dav_lock *lock);
  1456.  
  1457.     /*
  1458.     ** Remove any lock that has the specified locktoken.
  1459.     **
  1460.     ** If locktoken == NULL, then ALL locks are removed.
  1461.     */
  1462.     dav_error * (*remove_lock)(dav_lockdb *lockdb,
  1463.                                const dav_resource *resource,
  1464.                                const dav_locktoken *locktoken);
  1465.  
  1466.     /*
  1467.     ** Refresh all locks, found on the specified resource, which has a
  1468.     ** locktoken in the provided list.
  1469.     **
  1470.     ** If the lock is indirect, then the direct lock is referenced and
  1471.     ** refreshed.
  1472.     **
  1473.     ** Each lock that is updated is returned in the <locks> argument.
  1474.     ** Note that the locks will be fully resolved.
  1475.     */
  1476.     dav_error * (*refresh_locks)(dav_lockdb *lockdb,
  1477.                                  const dav_resource *resource,
  1478.                                  const dav_locktoken_list *ltl,
  1479.                                  time_t new_time,
  1480.                                  dav_lock **locks);
  1481.  
  1482.     /*
  1483.     ** Look up the resource associated with a particular locktoken.
  1484.     **
  1485.     ** The search begins at the specified <start_resource> and the lock
  1486.     ** specified by <locktoken>.
  1487.     **
  1488.     ** If the resource/token specifies an indirect lock, then the direct
  1489.     ** lock will be looked up, and THAT resource will be returned. In other
  1490.     ** words, this function always returns the resource where a particular
  1491.     ** lock (token) was asserted.
  1492.     **
  1493.     ** NOTE: this function pointer is allowed to be NULL, indicating that
  1494.     **       the provider does not support this type of functionality. The
  1495.     **       caller should then traverse up the repository hierarchy looking
  1496.     **       for the resource defining a lock with this locktoken.
  1497.     */
  1498.     dav_error * (*lookup_resource)(dav_lockdb *lockdb,
  1499.                                    const dav_locktoken *locktoken,
  1500.                                    const dav_resource *start_resource,
  1501.                                    const dav_resource **resource);
  1502.  
  1503.     /*
  1504.     ** If a provider needs a context to associate with this hooks structure,
  1505.     ** then this field may be used. In most cases, it will just be NULL.
  1506.     */
  1507.     void *ctx;
  1508. };
  1509.  
  1510. /* what types of resources can be discovered by dav_get_resource_state() */
  1511. #define DAV_RESOURCE_LOCK_NULL  10    /* resource lock-null */
  1512. #define DAV_RESOURCE_NULL       11    /* resource null */
  1513. #define DAV_RESOURCE_EXISTS     12    /* resource exists */
  1514. #define DAV_RESOURCE_ERROR      13    /* an error occurred */
  1515.  
  1516.  
  1517. /* --------------------------------------------------------------------
  1518. **
  1519. ** PROPERTY HANDLING
  1520. */
  1521.  
  1522. typedef struct dav_propdb dav_propdb;
  1523.  
  1524.  
  1525. dav_error *dav_open_propdb(
  1526.     request_rec *r,
  1527.     dav_lockdb *lockdb,
  1528.     const dav_resource *resource,
  1529.     int ro,
  1530.     apr_array_header_t *ns_xlate,
  1531.     dav_propdb **propdb);
  1532.  
  1533. void dav_close_propdb(dav_propdb *db);
  1534.  
  1535. dav_get_props_result dav_get_props(
  1536.     dav_propdb *db,
  1537.     apr_xml_doc *doc);
  1538.  
  1539. dav_get_props_result dav_get_allprops(
  1540.     dav_propdb *db,
  1541.     dav_prop_insert what);
  1542.  
  1543. void dav_get_liveprop_supported(
  1544.     dav_propdb *propdb,
  1545.     const char *ns_uri,
  1546.     const char *propname,
  1547.     apr_text_header *body);
  1548.  
  1549. /*
  1550. ** 3-phase property modification.
  1551. **
  1552. **   1) validate props. readable? unlocked? ACLs allow access?
  1553. **   2) execute operation (set/delete)
  1554. **   3) commit or rollback
  1555. **
  1556. ** ### eventually, auth must be available. a ref to the request_rec (which
  1557. ** ### contains the auth info) should be in the shared context struct.
  1558. **
  1559. ** Each function may alter the error values and information contained within
  1560. ** the context record. This should be done as an "increasing" level of
  1561. ** error, rather than overwriting any previous error.
  1562. **
  1563. ** Note that commit() cannot generate errors. It should simply free the
  1564. ** rollback information.
  1565. **
  1566. ** rollback() may generate additional errors because the rollback operation
  1567. ** can sometimes fail(!).
  1568. **
  1569. ** The caller should allocate an array of these, one per operation. It should
  1570. ** be zero-initialized, then the db, operation, and prop fields should be
  1571. ** filled in before calling dav_prop_validate. Note that the set/delete
  1572. ** operations are order-dependent. For a given (logical) context, the same
  1573. ** pointer must be passed to each phase.
  1574. **
  1575. ** error_type is an internal value, but will have the same numeric value
  1576. ** for each possible "desc" value. This allows the caller to group the
  1577. ** descriptions via the error_type variable, rather than through string
  1578. ** comparisons. Note that "status" does not provide enough granularity to
  1579. ** differentiate/group the "desc" values.
  1580. **
  1581. ** Note that the propdb will maintain some (global) context across all
  1582. ** of the property change contexts. This implies that you can have only
  1583. ** one open transaction per propdb.
  1584. */
  1585. typedef struct dav_prop_ctx
  1586. {
  1587.     dav_propdb *propdb;
  1588.  
  1589.     int operation;
  1590. #define DAV_PROP_OP_SET        1    /* set a property value */
  1591. #define DAV_PROP_OP_DELETE     2    /* delete a prop value */
  1592. /* ### add a GET? */
  1593.  
  1594.     apr_xml_elem *prop;             /* property to affect */
  1595.  
  1596.     dav_error *err;                 /* error (if any) */
  1597.  
  1598.     /* private items to the propdb */
  1599.     int is_liveprop;
  1600.     void *liveprop_ctx;
  1601.     struct dav_rollback_item *rollback;  /* optional rollback info */
  1602.  
  1603.     /* private to mod_dav.c */
  1604.     request_rec *r;
  1605.  
  1606. } dav_prop_ctx;
  1607.  
  1608. void dav_prop_validate(dav_prop_ctx *ctx);
  1609. void dav_prop_exec(dav_prop_ctx *ctx);
  1610. void dav_prop_commit(dav_prop_ctx *ctx);
  1611. void dav_prop_rollback(dav_prop_ctx *ctx);
  1612.  
  1613. #define DAV_PROP_CTX_HAS_ERR(dpc)  ((dpc).err && (dpc).err->status >= 300)
  1614.  
  1615.  
  1616. /* --------------------------------------------------------------------
  1617. **
  1618. ** WALKER STRUCTURE
  1619. */
  1620.  
  1621. enum {
  1622.     DAV_CALLTYPE_MEMBER = 1,    /* called for a member resource */
  1623.     DAV_CALLTYPE_COLLECTION,    /* called for a collection */
  1624.     DAV_CALLTYPE_LOCKNULL       /* called for a locknull resource */
  1625. };
  1626.  
  1627. typedef struct
  1628. {
  1629.     /* the client-provided context */
  1630.     void *walk_ctx;
  1631.  
  1632.     /* pool to use for allocations in the callback */
  1633.     apr_pool_t *pool;
  1634.  
  1635.     /* the current resource */
  1636.     const dav_resource *resource;
  1637.  
  1638.     /* OUTPUT: add responses to this */
  1639.     dav_response *response;
  1640.  
  1641. } dav_walk_resource;
  1642.  
  1643. typedef struct
  1644. {
  1645.     int walk_type;
  1646. #define DAV_WALKTYPE_AUTH       0x0001  /* limit to authorized files */
  1647. #define DAV_WALKTYPE_NORMAL     0x0002  /* walk normal files */
  1648. #define DAV_WALKTYPE_LOCKNULL   0x0004  /* walk locknull resources */
  1649.  
  1650.     /* callback function and a client context for the walk */
  1651.     dav_error * (*func)(dav_walk_resource *wres, int calltype);
  1652.     void *walk_ctx;
  1653.  
  1654.     /* what pool to use for allocations needed by walk logic */
  1655.     apr_pool_t *pool;
  1656.  
  1657.     /* beginning root of the walk */
  1658.     const dav_resource *root;
  1659.  
  1660.     /* lock database to enable walking LOCKNULL resources */
  1661.     dav_lockdb *lockdb;
  1662.  
  1663. } dav_walk_params;
  1664.  
  1665. /* directory tree walking context */
  1666. typedef struct dav_walker_ctx
  1667. {
  1668.     /* input: */
  1669.     dav_walk_params w;
  1670.  
  1671.  
  1672.     /* ### client data... phasing out this big glom */
  1673.  
  1674.     /* this brigade buffers data being sent to r->output_filters */ 
  1675.     apr_bucket_brigade *bb;
  1676.  
  1677.     /* a scratch pool, used to stream responses and iteratively cleared. */
  1678.     apr_pool_t *scratchpool;
  1679.  
  1680.     request_rec *r;                 /* original request */
  1681.  
  1682.     /* for PROPFIND operations */
  1683.     apr_xml_doc *doc;
  1684.     int propfind_type;
  1685. #define DAV_PROPFIND_IS_ALLPROP     1
  1686. #define DAV_PROPFIND_IS_PROPNAME    2
  1687. #define DAV_PROPFIND_IS_PROP        3
  1688.  
  1689.     apr_text *propstat_404;         /* (cached) propstat giving a 404 error */
  1690.  
  1691.     const dav_if_header *if_header; /* for validation */
  1692.     const dav_locktoken *locktoken; /* for UNLOCK */
  1693.     const dav_lock *lock;           /* for LOCK */
  1694.     int skip_root;                  /* for dav_inherit_locks() */
  1695.  
  1696.     int flags;
  1697.  
  1698.     dav_buffer work_buf;            /* for dav_validate_request() */
  1699.  
  1700. } dav_walker_ctx;
  1701.  
  1702. DAV_DECLARE(void) dav_add_response(dav_walk_resource *wres,
  1703.                                    int status,
  1704.                                    dav_get_props_result *propstats);
  1705.  
  1706.  
  1707. /* --------------------------------------------------------------------
  1708. **
  1709. ** "STREAM" STRUCTURE
  1710. **
  1711. ** mod_dav uses this abstraction for interacting with the repository
  1712. ** while fetching/storing resources. mod_dav views resources as a stream
  1713. ** of bytes.
  1714. **
  1715. ** Note that the structure is opaque -- it is private to the repository
  1716. ** that created the stream in the repository's "open" function.
  1717. **
  1718. ** ### THIS STUFF IS GOING AWAY ... GET/read requests are handled by
  1719. ** ### having the provider jam stuff straight into the filter stack.
  1720. ** ### this is only left for handling PUT/write requests.
  1721. */
  1722.  
  1723. typedef struct dav_stream dav_stream;
  1724.  
  1725. typedef enum {
  1726.     DAV_MODE_WRITE_TRUNC,      /* truncate and open for writing */
  1727.     DAV_MODE_WRITE_SEEKABLE    /* open for writing; random access */
  1728. } dav_stream_mode;
  1729.  
  1730.  
  1731. /* --------------------------------------------------------------------
  1732. **
  1733. ** REPOSITORY FUNCTIONS
  1734. */
  1735.  
  1736. /* Repository provider hooks */
  1737. struct dav_hooks_repository
  1738. {
  1739.     /* Flag for whether repository requires special GET handling.
  1740.      * If resources in the repository are not visible in the
  1741.      * filesystem location which URLs map to, then special handling
  1742.      * is required to first fetch a resource from the repository,
  1743.      * respond to the GET request, then free the resource copy.
  1744.      */
  1745.     int handle_get;
  1746.  
  1747.     /* Get a resource descriptor for the URI in a request. A descriptor
  1748.      * should always be returned even if the resource does not exist. This
  1749.      * repository has been identified as handling the resource given by
  1750.      * the URI, so an answer must be given. If there is a problem with the
  1751.      * URI or accessing the resource or whatever, then an error should be
  1752.      * returned.
  1753.      *
  1754.      * root_dir:
  1755.      *   the root of the directory for which this repository is configured.
  1756.      *
  1757.      * label:
  1758.      *   if a Label: header is present (and allowed), this is the label
  1759.      *   to use to identify a version resource from the resource's
  1760.      *   corresponding version history. Otherwise, it will be NULL.
  1761.      *
  1762.      * use_checked_in:
  1763.      *   use the DAV:checked-in property of the resource identified by the
  1764.      *   Request-URI to identify and return a version resource
  1765.      *
  1766.      * The provider may associate the request storage pool with the resource
  1767.      * (in the resource->pool field), to use in other operations on that
  1768.      * resource. 
  1769.      */
  1770.     dav_error * (*get_resource)(
  1771.         request_rec *r,
  1772.         const char *root_dir,
  1773.         const char *label,
  1774.         int use_checked_in,
  1775.         dav_resource **resource
  1776.     );
  1777.  
  1778.     /* Get a resource descriptor for the parent of the given resource.
  1779.      * The resources need not exist.  NULL is returned if the resource 
  1780.      * is the root collection.
  1781.      *
  1782.      * An error should be returned only if there is a fatal error in
  1783.      * fetching information about the parent resource.
  1784.      */
  1785.     dav_error * (*get_parent_resource)(
  1786.         const dav_resource *resource,
  1787.         dav_resource **parent_resource
  1788.     );
  1789.  
  1790.     /* Determine whether two resource descriptors refer to the same resource.
  1791.     *
  1792.      * Result != 0 => the resources are the same.
  1793.      */
  1794.     int (*is_same_resource)(
  1795.         const dav_resource *res1,
  1796.         const dav_resource *res2
  1797.     );
  1798.  
  1799.     /* Determine whether one resource is a parent (immediate or otherwise)
  1800.      * of another.
  1801.      *
  1802.      * Result != 0 => res1 is a parent of res2.
  1803.      */
  1804.     int (*is_parent_resource)(
  1805.         const dav_resource *res1,
  1806.         const dav_resource *res2
  1807.     );
  1808.  
  1809.     /*
  1810.     ** Open a stream for this resource, using the specified mode. The
  1811.     ** stream will be returned in *stream.
  1812.     */
  1813.     dav_error * (*open_stream)(const dav_resource *resource,
  1814.                                dav_stream_mode mode,
  1815.                                dav_stream **stream);
  1816.  
  1817.     /*
  1818.     ** Close the specified stream.
  1819.     **
  1820.     ** mod_dav will (ideally) make sure to call this. For safety purposes,
  1821.     ** a provider should (ideally) register a cleanup function with the
  1822.     ** request pool to get this closed and cleaned up.
  1823.     **
  1824.     ** Note the possibility of an error from the close -- it is entirely
  1825.     ** feasible that the close does a "commit" of some kind, which can
  1826.     ** produce an error.
  1827.     **
  1828.     ** commit should be TRUE (non-zero) or FALSE (0) if the stream was
  1829.     ** opened for writing. This flag states whether to retain the file
  1830.     ** or not.
  1831.     ** Note: the commit flag is ignored for streams opened for reading.
  1832.     */
  1833.     dav_error * (*close_stream)(dav_stream *stream, int commit);
  1834.  
  1835.     /*
  1836.     ** Write data to the stream.
  1837.     **
  1838.     ** All of the bytes must be written, or an error should be returned.
  1839.     */
  1840.     dav_error * (*write_stream)(dav_stream *stream,
  1841.                                 const void *buf, apr_size_t bufsize);
  1842.  
  1843.     /*
  1844.     ** Seek to an absolute position in the stream. This is used to support
  1845.     ** Content-Range in a GET/PUT.
  1846.     **
  1847.     ** NOTE: if this function is NULL (which is allowed), then any
  1848.     **       operations using Content-Range will be refused.
  1849.     */
  1850.     dav_error * (*seek_stream)(dav_stream *stream, apr_off_t abs_position);
  1851.  
  1852.     /*
  1853.     ** If a GET is processed using a stream (open_stream, read_stream)
  1854.     ** rather than via a sub-request (on get_pathname), then this function
  1855.     ** is used to provide the repository with a way to set the headers
  1856.     ** in the response.
  1857.     **
  1858.     ** This function may be called without a following deliver(), to
  1859.     ** handle a HEAD request.
  1860.     **
  1861.     ** This may be NULL if handle_get is FALSE.
  1862.     */
  1863.     dav_error * (*set_headers)(request_rec *r,
  1864.                                const dav_resource *resource);
  1865.  
  1866.     /*
  1867.     ** The provider should deliver the resource into the specified filter.
  1868.     ** Basically, this is the response to the GET method.
  1869.     **
  1870.     ** Note that this is called for all resources, including collections.
  1871.     ** The provider should determine what has content to deliver or not.
  1872.     **
  1873.     ** set_headers will be called prior to this function, allowing the
  1874.     ** provider to set the appropriate response headers.
  1875.     **
  1876.     ** This may be NULL if handle_get is FALSE.
  1877.     ** ### maybe toss handle_get and just use this function as the marker
  1878.     */
  1879.     dav_error * (*deliver)(const dav_resource *resource,
  1880.                            ap_filter_t *output);
  1881.  
  1882.     /* Create a collection resource. The resource must not already exist.
  1883.      *
  1884.      * Result == NULL if the collection was created successfully. Also, the
  1885.      * resource object is updated to reflect that the resource exists, and
  1886.      * is a collection.
  1887.      */
  1888.     dav_error * (*create_collection)(
  1889.         dav_resource *resource
  1890.     );
  1891.  
  1892.     /* Copy one resource to another. The destination may exist, if it is
  1893.      * versioned.
  1894.      * Handles both files and collections. Properties are copied as well.
  1895.      * If the destination exists and is versioned, the provider must update
  1896.      * the destination to have identical content to the source,
  1897.      * recursively for collections.
  1898.      * The depth argument is ignored for a file, and can be either 0 or
  1899.      * DAV_INFINITY for a collection.
  1900.      * If an error occurs in a child resource, then the return value is
  1901.      * non-NULL, and *response is set to a multistatus response.
  1902.      * If the copy is successful, the dst resource object is
  1903.      * updated to reflect that the resource exists.
  1904.      */
  1905.     dav_error * (*copy_resource)(
  1906.         const dav_resource *src,
  1907.         dav_resource *dst,
  1908.         int depth,
  1909.         dav_response **response
  1910.     );
  1911.  
  1912.     /* Move one resource to another. The destination must not exist.
  1913.      * Handles both files and collections. Properties are moved as well.
  1914.      * If an error occurs in a child resource, then the return value is
  1915.      * non-NULL, and *response is set to a multistatus response.
  1916.      * If the move is successful, the src and dst resource objects are
  1917.      * updated to reflect that the source no longer exists, and the
  1918.      * destination does.
  1919.      */
  1920.     dav_error * (*move_resource)(
  1921.         dav_resource *src,
  1922.         dav_resource *dst,
  1923.         dav_response **response
  1924.     );
  1925.  
  1926.     /* Remove a resource. Handles both files and collections.
  1927.      * Removes any associated properties as well.
  1928.      * If an error occurs in a child resource, then the return value is
  1929.      * non-NULL, and *response is set to a multistatus response.
  1930.      * If the delete is successful, the resource object is updated to
  1931.      * reflect that the resource no longer exists.
  1932.      */
  1933.     dav_error * (*remove_resource)(
  1934.         dav_resource *resource,
  1935.         dav_response **response
  1936.     );
  1937.  
  1938.     /* Walk a resource hierarchy.
  1939.      *
  1940.      * Iterates over the resource hierarchy specified by params->root.
  1941.      * Control of the walk and the callback are specified by 'params'.
  1942.      *
  1943.      * An error may be returned. *response will contain multistatus
  1944.      * responses (if any) suitable for the body of the error. It is also
  1945.      * possible to return NULL, yet still have multistatus responses.
  1946.      * In this case, typically the caller should return a 207 (Multistatus)
  1947.      * and the responses (in the body) as the HTTP response.
  1948.      */
  1949.     dav_error * (*walk)(const dav_walk_params *params, int depth,
  1950.                         dav_response **response);
  1951.  
  1952.     /* Get the entity tag for a resource */
  1953.     const char * (*getetag)(const dav_resource *resource);
  1954.  
  1955.     /*
  1956.     ** If a provider needs a context to associate with this hooks structure,
  1957.     ** then this field may be used. In most cases, it will just be NULL.
  1958.     */
  1959.     void *ctx;
  1960. };
  1961.  
  1962.  
  1963. /* --------------------------------------------------------------------
  1964. **
  1965. ** VERSIONING FUNCTIONS
  1966. */
  1967.  
  1968.  
  1969. /* dav_add_vary_header
  1970.  *
  1971.  * If there were any headers in the request which require a Vary header
  1972.  * in the response, add it.
  1973.  */
  1974. void dav_add_vary_header(request_rec *in_req,
  1975.                          request_rec *out_req,
  1976.                          const dav_resource *resource);
  1977.  
  1978. /*
  1979. ** Flags specifying auto-versioning behavior, returned by
  1980. ** the auto_versionable hook. The value returned depends
  1981. ** on both the state of the resource and the value of the
  1982. ** DAV:auto-versioning property for the resource.
  1983. **
  1984. ** If the resource does not exist (null or lock-null),
  1985. ** DAV_AUTO_VERSION_ALWAYS causes creation of a new version-controlled resource
  1986. **
  1987. ** If the resource is checked in,
  1988. ** DAV_AUTO_VERSION_ALWAYS causes it to be checked out always,
  1989. ** DAV_AUTO_VERSION_LOCKED causes it to be checked out only when locked
  1990. **
  1991. ** If the resource is checked out,
  1992. ** DAV_AUTO_VERSION_ALWAYS causes it to be checked in always,
  1993. ** DAV_AUTO_VERSION_LOCKED causes it to be checked in when unlocked
  1994. ** (note: a provider should allow auto-checkin only for resources which
  1995. ** were automatically checked out)
  1996. **
  1997. ** In all cases, DAV_AUTO_VERSION_NEVER results in no auto-versioning behavior.
  1998. */
  1999. typedef enum {
  2000.     DAV_AUTO_VERSION_NEVER,
  2001.     DAV_AUTO_VERSION_ALWAYS,
  2002.     DAV_AUTO_VERSION_LOCKED
  2003. } dav_auto_version;
  2004.  
  2005. /*
  2006. ** This structure is used to record what auto-versioning operations
  2007. ** were done to make a resource writable, so that they can be undone
  2008. ** at the end of a request.
  2009. */
  2010. typedef struct {
  2011.     int resource_versioned;             /* 1 => resource was auto-version-controlled */
  2012.     int resource_checkedout;            /* 1 => resource was auto-checked-out */
  2013.     int parent_checkedout;              /* 1 => parent was auto-checked-out */
  2014.     dav_resource *parent_resource;      /* parent resource, if it was needed */
  2015. } dav_auto_version_info;
  2016.  
  2017. /* Ensure that a resource is writable. If there is no versioning
  2018.  * provider, then this is essentially a no-op. Versioning repositories
  2019.  * require explicit resource creation and checkout before they can
  2020.  * be written to. If a new resource is to be created, or an existing
  2021.  * resource deleted, the parent collection must be checked out as well.
  2022.  *
  2023.  * Set the parent_only flag to only make the parent collection writable.
  2024.  * Otherwise, both parent and child are made writable as needed. If the
  2025.  * child does not exist, then a new versioned resource is created and
  2026.  * checked out.
  2027.  *
  2028.  * If auto-versioning is not enabled for a versioned resource, then an error is
  2029.  * returned, since the resource cannot be modified.
  2030.  *
  2031.  * The dav_auto_version_info structure is filled in with enough information
  2032.  * to restore both parent and child resources to the state they were in
  2033.  * before the auto-versioning operations occurred.
  2034.  */
  2035. dav_error *dav_auto_checkout(
  2036.     request_rec *r,
  2037.     dav_resource *resource,
  2038.     int parent_only,
  2039.     dav_auto_version_info *av_info);
  2040.  
  2041. /* Revert the writability of resources back to what they were
  2042.  * before they were modified. If undo == 0, then the resource
  2043.  * modifications are maintained (i.e. they are checked in).
  2044.  * If undo != 0, then resource modifications are discarded
  2045.  * (i.e. they are unchecked out).
  2046.  *
  2047.  * Set the unlock flag to indicate that the resource is about
  2048.  * to be unlocked; it will be checked in if the resource
  2049.  * auto-versioning property indicates it should be. In this case,
  2050.  * av_info is ignored, so it can be NULL.
  2051.  *
  2052.  * The resource argument may be NULL if only the parent resource
  2053.  * was checked out (i.e. the parent_only was != 0 in the
  2054.  * dav_auto_checkout call).
  2055.  */
  2056. dav_error *dav_auto_checkin(
  2057.     request_rec *r,
  2058.     dav_resource *resource,
  2059.     int undo,
  2060.     int unlock,
  2061.     dav_auto_version_info *av_info);
  2062.  
  2063. /*
  2064. ** This structure is used to describe available reports
  2065. **
  2066. ** "nmspace" should be valid XML and URL-quoted. mod_dav will place
  2067. ** double-quotes around it and use it in an xmlns declaration.
  2068. */
  2069. typedef struct {
  2070.     const char *nmspace;        /* namespace of the XML report element */
  2071.     const char *name;           /* element name for the XML report */
  2072. } dav_report_elem;
  2073.  
  2074.  
  2075. /* Versioning provider hooks */
  2076. struct dav_hooks_vsn
  2077. {
  2078.     /*
  2079.     ** MANDATORY HOOKS
  2080.     ** The following hooks are mandatory for all versioning providers;
  2081.     ** they define the functionality needed to implement "core" versioning.
  2082.     */
  2083.  
  2084.     /* Return supported versioning options.
  2085.      * Each dav_text item in the list will be returned as a separate
  2086.      * DAV header. Providers are advised to limit the length of an
  2087.      * individual text item to 63 characters, to conform to the limit
  2088.      * used by MS Web Folders.
  2089.      */
  2090.     void (*get_vsn_options)(apr_pool_t *p, apr_text_header *phdr);
  2091.  
  2092.     /* Get the value of a specific option for an OPTIONS request.
  2093.      * The option being requested is given by the parsed XML
  2094.      * element object "elem". The value of the option should be
  2095.      * appended to the "option" text object.
  2096.      */
  2097.     dav_error * (*get_option)(const dav_resource *resource,
  2098.                               const apr_xml_elem *elem,
  2099.                               apr_text_header *option);
  2100.  
  2101.     /* Determine whether a non-versioned (or non-existent) resource
  2102.      * is versionable. Returns != 0 if resource can be versioned.
  2103.      */
  2104.     int (*versionable)(const dav_resource *resource);
  2105.  
  2106.     /* Determine whether auto-versioning is enabled for a resource
  2107.      * (which may not exist, or may not be versioned). If the resource
  2108.      * is a checked-out resource, the provider must only enable
  2109.      * auto-checkin if the resource was automatically checked out.
  2110.      *
  2111.      * The value returned depends on both the state of the resource
  2112.      * and the value of its DAV:auto-version property. See the description
  2113.      * of the dav_auto_version enumeration above for the details.
  2114.      */
  2115.     dav_auto_version (*auto_versionable)(const dav_resource *resource);
  2116.  
  2117.     /* Put a resource under version control. If the resource already
  2118.      * exists unversioned, then it becomes the initial version of the
  2119.      * new version history, and it is replaced by a version selector
  2120.      * which targets the new version.
  2121.      *
  2122.      * If the resource does not exist, then a new version-controlled
  2123.      * resource is created which either targets an existing version (if the
  2124.      * "target" argument is not NULL), or the initial, empty version
  2125.      * in a new history resource (if the "target" argument is NULL).
  2126.      *
  2127.      * If successful, the resource object state is updated appropriately
  2128.      * (that is, changed to refer to the new version-controlled resource).
  2129.      */
  2130.     dav_error * (*vsn_control)(dav_resource *resource,
  2131.                                const char *target);
  2132.  
  2133.     /* Checkout a resource. If successful, the resource
  2134.      * object state is updated appropriately.
  2135.      *
  2136.      * The auto_checkout flag will be set if this checkout is being
  2137.      * done automatically, as part of some method which modifies
  2138.      * the resource. The provider must remember that the resource
  2139.      * was automatically checked out, so it can determine whether it
  2140.      * can be automatically checked in. (Auto-checkin should only be
  2141.      * enabled for resources which were automatically checked out.)
  2142.      *
  2143.      * If the working resource has a different URL from the
  2144.      * target resource, a dav_resource descriptor is returned
  2145.      * for the new working resource. Otherwise, the original
  2146.      * resource descriptor will refer to the working resource.
  2147.      * The working_resource argument can be NULL if the caller
  2148.      * is not interested in the working resource.
  2149.      *
  2150.      * If the client has specified DAV:unreserved or DAV:fork-ok in the
  2151.      * checkout request, then the corresponding flags are set. If
  2152.      * DAV:activity-set has been specified, then create_activity is set
  2153.      * if DAV:new was specified; otherwise, the DAV:href elements' CDATA
  2154.      * (the actual href text) is passed in the "activities" array (each
  2155.      * element of the array is a const char *). activities will be NULL
  2156.      * no DAV:activity-set was provided or when create_activity is set.
  2157.      */
  2158.     dav_error * (*checkout)(dav_resource *resource,
  2159.                             int auto_checkout,
  2160.                             int is_unreserved, int is_fork_ok,
  2161.                             int create_activity,
  2162.                             apr_array_header_t *activities,
  2163.                             dav_resource **working_resource);
  2164.  
  2165.     /* Uncheckout a checked-out resource. If successful, the resource
  2166.      * object state is updated appropriately.
  2167.      */
  2168.     dav_error * (*uncheckout)(dav_resource *resource);
  2169.  
  2170.     /* Checkin a checked-out resource. If successful, the resource
  2171.      * object state is updated appropriately, and the
  2172.      * version_resource descriptor will refer to the new version.
  2173.      * The version_resource argument can be NULL if the caller
  2174.      * is not interested in the new version resource.
  2175.      *
  2176.      * If the client has specified DAV:keep-checked-out in the checkin
  2177.      * request, then the keep_checked_out flag is set. The provider
  2178.      * should create a new version, but keep the resource in the
  2179.      * checked-out state.
  2180.      */
  2181.     dav_error * (*checkin)(dav_resource *resource,
  2182.                            int keep_checked_out,
  2183.                            dav_resource **version_resource);
  2184.  
  2185.     /*
  2186.     ** Return the set of reports available at this resource.
  2187.     **
  2188.     ** An array of report elements should be returned, with an end-marker
  2189.     ** element containing namespace==NULL. The value of the
  2190.     ** DAV:supported-report-set property will be constructed and
  2191.     ** returned.
  2192.     */
  2193.     dav_error * (*avail_reports)(const dav_resource *resource,
  2194.                                  const dav_report_elem **reports);
  2195.  
  2196.     /*
  2197.     ** Determine whether a Label header can be used
  2198.     ** with a particular report. The dav_xml_doc structure
  2199.     ** contains the parsed report request body.
  2200.     ** Returns 0 if the Label header is not allowed.
  2201.     */
  2202.     int (*report_label_header_allowed)(const apr_xml_doc *doc);
  2203.  
  2204.     /*
  2205.     ** Generate a report on a resource. Since a provider is free
  2206.     ** to define its own reports, and the value of request headers
  2207.     ** may affect the interpretation of a report, the request record
  2208.     ** must be passed to this routine.
  2209.     **
  2210.     ** The dav_xml_doc structure contains the parsed report request
  2211.     ** body. The report response should be generated into the specified
  2212.     ** output filter.
  2213.     **
  2214.     ** If an error occurs, and a response has not yet been generated,
  2215.     ** then an error can be returned from this function. mod_dav will
  2216.     ** construct an appropriate error response. Once some output has
  2217.     ** been placed into the filter, however, the provider should not
  2218.     ** return an error -- there is no way that mod_dav can deliver it
  2219.     ** properly.
  2220.     **
  2221.     ** ### maybe we need a way to signal an error anyways, and then
  2222.     ** ### apache can abort the connection?
  2223.     */
  2224.     dav_error * (*deliver_report)(request_rec *r,
  2225.                                   const dav_resource *resource,
  2226.                                   const apr_xml_doc *doc,
  2227.                                   ap_filter_t *output);
  2228.  
  2229.     /*
  2230.     ** OPTIONAL HOOKS
  2231.     ** The following hooks are optional; if not defined, then the
  2232.     ** corresponding protocol methods will be unsupported.
  2233.     */
  2234.  
  2235.     /*
  2236.     ** Set the state of a checked-in version-controlled resource.
  2237.     **
  2238.     ** If the request specified a version, the version resource
  2239.     ** represents that version. If the request specified a label,
  2240.     ** then "version" is NULL, and "label" is the label.
  2241.     **
  2242.     ** The depth argument is ignored for a file, and can be 0, 1, or
  2243.     ** DAV_INFINITY for a collection. The depth argument only applies
  2244.     ** with a label, not a version.
  2245.     **
  2246.     ** If an error occurs in a child resource, then the return value is
  2247.     ** non-NULL, and *response is set to a multistatus response.
  2248.     **
  2249.     ** This hook is optional; if not defined, then the UPDATE method
  2250.     ** will not be supported.
  2251.     */
  2252.     dav_error * (*update)(const dav_resource *resource,
  2253.                           const dav_resource *version,
  2254.                           const char *label,
  2255.                           int depth,
  2256.                           dav_response **response);
  2257.  
  2258.     /*
  2259.     ** Add a label to a version. The resource is either a specific
  2260.     ** version, or a version selector, in which case the label should
  2261.     ** be added to the current target of the version selector. The
  2262.     ** version selector cannot be checked out.
  2263.     **
  2264.     ** If replace != 0, any existing label by the same name is
  2265.     ** effectively deleted first. Otherwise, it is an error to
  2266.     ** attempt to add a label which already exists on some version
  2267.     ** of the same history resource.
  2268.     **
  2269.     ** This hook is optional; if not defined, then the LABEL method
  2270.     ** will not be supported. If it is defined, then the remove_label
  2271.     ** hook must be defined also.
  2272.     */
  2273.     dav_error * (*add_label)(const dav_resource *resource,
  2274.                              const char *label,
  2275.                              int replace);
  2276.  
  2277.     /*
  2278.     ** Remove a label from a version. The resource is either a specific
  2279.     ** version, or a version selector, in which case the label should
  2280.     ** be added to the current target of the version selector. The
  2281.     ** version selector cannot be checked out.
  2282.     **
  2283.     ** It is an error if no such label exists on the specified version.
  2284.     **
  2285.     ** This hook is optional, but if defined, the add_label hook
  2286.     ** must be defined also.
  2287.     */
  2288.     dav_error * (*remove_label)(const dav_resource *resource,
  2289.                                 const char *label);
  2290.  
  2291.     /*
  2292.     ** Determine whether a null resource can be created as a workspace.
  2293.     ** The provider may restrict workspaces to certain locations.
  2294.     ** Returns 0 if the resource cannot be a workspace.
  2295.     **
  2296.     ** This hook is optional; if the provider does not support workspaces,
  2297.     ** it should be set to NULL.
  2298.     */
  2299.     int (*can_be_workspace)(const dav_resource *resource);
  2300.  
  2301.     /*
  2302.     ** Create a workspace resource. The resource must not already
  2303.     ** exist. Any <DAV:mkworkspace> element is passed to the provider
  2304.     ** in the "doc" structure; it may be empty.
  2305.     **
  2306.     ** If workspace creation is succesful, the state of the resource
  2307.     ** object is updated appropriately.
  2308.     **
  2309.     ** This hook is optional; if the provider does not support workspaces,
  2310.     ** it should be set to NULL.
  2311.     */
  2312.     dav_error * (*make_workspace)(dav_resource *resource,
  2313.                                   apr_xml_doc *doc);
  2314.  
  2315.     /*
  2316.     ** Determine whether a null resource can be created as an activity.
  2317.     ** The provider may restrict activities to certain locations.
  2318.     ** Returns 0 if the resource cannot be an activity.
  2319.     **
  2320.     ** This hook is optional; if the provider does not support activities,
  2321.     ** it should be set to NULL.
  2322.     */
  2323.     int (*can_be_activity)(const dav_resource *resource);
  2324.  
  2325.     /*
  2326.     ** Create an activity resource. The resource must not already
  2327.     ** exist.
  2328.     **
  2329.     ** If activity creation is succesful, the state of the resource
  2330.     ** object is updated appropriately.
  2331.     **
  2332.     ** This hook is optional; if the provider does not support activities,
  2333.     ** it should be set to NULL.
  2334.     */
  2335.     dav_error * (*make_activity)(dav_resource *resource);
  2336.  
  2337.     /*
  2338.     ** Merge a resource (tree) into target resource (tree).
  2339.     **
  2340.     ** ### more doc...
  2341.     **
  2342.     ** This hook is optional; if the provider does not support merging,
  2343.     ** then this should be set to NULL.
  2344.     */
  2345.     dav_error * (*merge)(dav_resource *target, dav_resource *source,
  2346.                          int no_auto_merge, int no_checkout,
  2347.                          apr_xml_elem *prop_elem,
  2348.                          ap_filter_t *output);
  2349.  
  2350.     /*
  2351.     ** If a provider needs a context to associate with this hooks structure,
  2352.     ** then this field may be used. In most cases, it will just be NULL.
  2353.     */
  2354.     void *ctx;
  2355. };
  2356.  
  2357.  
  2358. /* --------------------------------------------------------------------
  2359. **
  2360. ** BINDING FUNCTIONS
  2361. */
  2362.  
  2363. /* binding provider hooks */
  2364. struct dav_hooks_binding {
  2365.  
  2366.     /* Determine whether a resource can be the target of a binding.
  2367.      * Returns 0 if the resource cannot be a binding target.
  2368.      */
  2369.     int (*is_bindable)(const dav_resource *resource);
  2370.  
  2371.     /* Create a binding to a resource.
  2372.      * The resource argument is the target of the binding;
  2373.      * the binding argument must be a resource which does not already
  2374.      * exist.
  2375.      */
  2376.     dav_error * (*bind_resource)(const dav_resource *resource,
  2377.                                  dav_resource *binding);
  2378.  
  2379.     /*
  2380.     ** If a provider needs a context to associate with this hooks structure,
  2381.     ** then this field may be used. In most cases, it will just be NULL.
  2382.     */
  2383.     void *ctx;
  2384.  
  2385. };
  2386.  
  2387.  
  2388. /* --------------------------------------------------------------------
  2389. **
  2390. ** SEARCH(DASL) FUNCTIONS
  2391. */
  2392.  
  2393. /* search provider hooks */
  2394. struct dav_hooks_search {
  2395.     /* Set header for a OPTION method
  2396.      * An error may be returned.
  2397.      * To set a hadder, this function might call
  2398.      * apr_table_setn(r->headers_out, "DASL", dasl_optin1);
  2399.      *
  2400.      * Examples:
  2401.      * DASL: <DAV:basicsearch>
  2402.      * DASL: <http://foo.bar.com/syntax1>
  2403.      * DASL: <http://akuma.com/syntax2>
  2404.      */
  2405.     dav_error * (*set_option_head)(request_rec *r);
  2406.  
  2407.     /* Search resources
  2408.      * An error may be returned. *response will contain multistatus
  2409.      * responses (if any) suitable for the body of the error. It is also
  2410.      * possible to return NULL, yet still have multistatus responses.
  2411.      * In this case, typically the caller should return a 207 (Multistatus)
  2412.      * and the responses (in the body) as the HTTP response.
  2413.      */
  2414.     dav_error * (*search_resource)(request_rec *r,
  2415.                                    dav_response **response);
  2416.  
  2417.     /*
  2418.     ** If a provider needs a context to associate with this hooks structure,
  2419.     ** then this field may be used. In most cases, it will just be NULL.
  2420.     */
  2421.     void *ctx;
  2422.  
  2423. };
  2424.  
  2425.  
  2426. /* --------------------------------------------------------------------
  2427. **
  2428. ** MISCELLANEOUS STUFF
  2429. */
  2430.  
  2431. /* fetch the "LimitXMLRequestBody" in force for this resource */
  2432. apr_size_t dav_get_limit_xml_body(const request_rec *r);
  2433.  
  2434. typedef struct {
  2435.     int propid;                          /* live property ID */
  2436.     const dav_hooks_liveprop *provider;  /* the provider defining this prop */
  2437. } dav_elem_private;    
  2438.  
  2439. #ifdef __cplusplus
  2440. }
  2441. #endif
  2442.  
  2443. #endif /* _MOD_DAV_H_ */
  2444.